package com.kang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kang.entity.Park;
import com.kang.mapper.ParkMapper;
import com.kang.service.ParkService;
import com.kang.vo.ParamInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ParkServiceMapper extends ServiceImpl<ParkMapper, Park> implements ParkService {

    @Autowired
    private ParkMapper parkMapper;

    @Override
    public Integer updateStatus(Integer id) {
        UpdateWrapper<Park> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("status",2);
        wrapper.set("create_time",new Date());
        return parkMapper.update(null,wrapper);
    }

    @Override
    public Integer refusePark(Integer id) {
        UpdateWrapper<Park> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("status",3);
        return parkMapper.update(null,wrapper);
    }

    @Override
    public Page<Park> getAuditParkPage(ParamInfo paramInfo) {
        Page<Park> page = new Page<>(paramInfo.getPageNum(), paramInfo.getPageSize());
        QueryWrapper<Park> wrapper = new QueryWrapper<>();
        wrapper.eq("status",1);
        wrapper.between(paramInfo.getStartTime() != null,"create_time",paramInfo.getStartTime(),paramInfo.getEndTime());
        return parkMapper.selectPage(page, wrapper);

    }


}
